package com.pl.service.impl;  

import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pl.bean.ManageRoleBean;
import com.pl.dao.ManageRoleBeanDao;
import com.pl.service.ManageRoleService;

import javax.annotation.Resource;

/**
 * 
 */
@Service("manageRoleService")
public class ManageRoleServiceImpl implements ManageRoleService{

	private static Logger log = LogManager.getLogger();

	@Resource(name="manageRoleBeanDao")
	private ManageRoleBeanDao manageRoleBeanDao;

	/**
	 * 新增
	 */
	@Transactional
	public void addManageRole(ManageRoleBean manageRoleBean){
		
		manageRoleBeanDao.addManageRoleBean(manageRoleBean);
	}

	/**
	 * 修改
	 */
	@Transactional
	public void updateManageRole(ManageRoleBean manageRoleBean){
		
		manageRoleBeanDao.updateManageRoleBean(manageRoleBean);
	}
	
	/**
	 * 根据条件获得数量
	 */
	public int getManageRoleNum(ManageRoleBean manageRoleBean){
		
		return manageRoleBeanDao.getManageRoleBeanNum(manageRoleBean);
	}
	
	/**
	 * 根据条件获得数据
	 */
	public List<ManageRoleBean> getManageRole(ManageRoleBean manageRoleBean){
		
		return manageRoleBeanDao.getManageRoleBean(manageRoleBean);
	}
	
	/**
	 * 根据条件获得数据
	 */
	public ManageRoleBean getManageRoleById(Long id){
		
		ManageRoleBean manageRoleBean = new ManageRoleBean();
		manageRoleBean.setId(id);
		
		List<ManageRoleBean> list = getManageRole(manageRoleBean);
		if(list !=null && !list.isEmpty()){
    		return list.get(0);
    	}
    	
    	return null;
	}

	@Override
	public ManageRoleBean getManageRole(String clientId, String code) {
		
		ManageRoleBean param = new ManageRoleBean();
		param.setClient_id(clientId);
		param.setCode(code);
		
		List<ManageRoleBean> list = getManageRole(param);
		if(list !=null && !list.isEmpty() && list.size() == 1){
    		return list.get(0);
    	}
    	
    	return null;
	}
}
